#ifndef __CE_GFX_MESH_INSTANCEDMESH_H__
#define __CE_GFX_MESH_INSTANCEDMESH_H__

#include <gfx/iinstancedmesh.h>
#include <math/boundingbox.h>


class ceMesh;
struct iDevice;
struct iLevelOfDetailSolver;

/**
 * \addtogroup opengl
 * @{
 */
/**
 * @brief Abstract base implmentation of the iInstancedMesh
 */
class ceInstancedMeshGL20 : public iInstancedMesh
{

protected:
  
  ceBoundingBox           _bbox;
  ceMesh*                 _mesh;

  std::vector<ceInstancedData>				_instanceData;

  unsigned                _instanceCount;
  unsigned                _instanceUse;
  iLevelOfDetailSolver*  _lodSolver;
	iInstanceGenerator*			_generator;

public:
  ceInstancedMeshGL20();
  virtual ~ceInstancedMeshGL20();

  virtual void Update (const ceRenderEnvironment& renderEnvironment, iDevice* device);

  void UpdateBoundingBox ();
  virtual void SetBoundingBox (const ceBoundingBox& bbox)
	{
		_bbox = bbox;
	}

  void SetMesh (ceMesh* mesh);
  const ceMesh* GetMesh () const;
  ceMesh* GetMesh();

  const ceBoundingBox& GetBoundingBox () const
  {
    return _bbox;
  }

  ceBoundingBox& GetBoundingBox ()
  {
    return _bbox;
  }

  inline void SetLevelOfDetailSolver (iLevelOfDetailSolver* solver)
  {
    _lodSolver = solver;
  }
  inline iLevelOfDetailSolver* GetLevelOfDetailSolver ()
  {
    return _lodSolver;
  }

	inline void SetInstanceGenerator (iInstanceGenerator* generator)
	{
		_generator = generator;
	}

	inline iInstanceGenerator* GetInstanceGenerator () const
	{
		return _generator;
	}

  void SetNumberOfInstances (unsigned instanceCount)
  {
    _instanceCount = instanceCount;
    _instanceUse = instanceCount;
  }

  unsigned GetNumberOfInstances () const
  {
    return _instanceCount;
  }

  virtual void AddInstanceData (const ceInstancedData& data);
  virtual const ceInstancedData& GetInstanceData (unsigned idx) const;
	virtual unsigned GetNumberOfInstanceData () const;

};

/** @} */

#endif // __CE_GFX_MESH_INSTANCEDMESH_H__
